package cn.zhonghuanzhiyuan.sprc.basicinfo.controller;

import cn.org.bachelor.web.json.JsonResponse;

import cn.zhonghuanzhiyuan.sprc.basicinfo.domain.SafeLicense;
import cn.zhonghuanzhiyuan.sprc.basicinfo.pojo.vo.*;
import cn.zhonghuanzhiyuan.sprc.basicinfo.service.SafeLicenseService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 企业安全许可证(SafeLicense)控制层
 *
 * @author david
 * @since 2024-02-27 21:19:28
 */
@Api(tags = "企业安全许可证控制层")
@RestController
@RequestMapping("/safeLicense")
@CrossOrigin // 线上不需要 （要注掉）
public class SafeLicenseController {
    /**
     * 服务对象
     */
    @Autowired
    private SafeLicenseService safeLicenseService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "获取企业安全许可证单条数据")
    @GetMapping("/getSafeLicenseById/{id}")
    public HttpEntity<JsonResponse> getSafeLicenseById(@ApiParam(name = "id", value = "编号", required = true) @PathVariable String id) {
        SafeLicense safeLicense = safeLicenseService.getSafeLicenseById(id);
        return JsonResponse.createHttpEntity(safeLicense, HttpStatus.OK);
    }

    /**
     * 分页查询
     *
     * @param querySafeLicenseVo
     * @return PageInfo<SafeLicense>
     */
    @ApiOperation(value = "获取企业安全许可证分页数据")
    @PostMapping("/getSafeLicensePage")
    public HttpEntity<JsonResponse> getSafeLicensePage(@ApiParam(name = "querySafeLicenseVo", value = "企业安全许可证", required = true) @RequestBody QuerySafeLicenseVo querySafeLicenseVo) {
        PageHelper.startPage(querySafeLicenseVo.getPageNum(), querySafeLicenseVo.getPageSize());
        List<SafeLicense> list = safeLicenseService.selectSafeLicenseList(querySafeLicenseVo);
        return JsonResponse.createHttpEntity(new PageInfo<>(list), HttpStatus.OK);
    }

    /**
     * 导出查询
     *
     * @param querySafeLicenseVo
     * @return SafeLicense
     */
    @ApiOperation(value = "获取企业安全许可证导出数据")
    @PostMapping("/getSafeLicenseList")
    public HttpEntity<JsonResponse> getSafeLicenseList(@ApiParam(name = "querySafeLicenseVo", value = "企业安全许可证", required = true) @RequestBody QuerySafeLicenseVo querySafeLicenseVo) {
        List<SafeLicense> list = safeLicenseService.selectSafeLicenseList(querySafeLicenseVo);
        return JsonResponse.createHttpEntity(list, HttpStatus.OK);
    }

    /**
     * 新增或保存
     *
     * @param
     * @return
     */
    @ApiOperation(value = "修改或新增企业安全许可证")
    @PostMapping("/updateOrSaveSafeLicense")
    public HttpEntity<JsonResponse> updateOrSaveSafeLicense(@ApiParam(name = "updateOrSaveSafeLicenseVo", value = "企业安全许可证", required = true) @RequestBody UpdateOrSaveSafeLicenseVo updateOrSaveSafeLicenseVo) {
        safeLicenseService.insertOrUpdate(updateOrSaveSafeLicenseVo);
        return JsonResponse.createHttpEntity(HttpStatus.OK);
    }


    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "批量删除企业安全许可证")
    @DeleteMapping("/deleteSafeLicenseByIds/{ids}")
    public HttpEntity<JsonResponse> deleteSafeLicenseByIds(@ApiParam(name = "idList", value = "主键集合", required = true) @PathVariable String ids) {
        safeLicenseService.deleteByIds(ids);
        return JsonResponse.createHttpEntity(HttpStatus.OK);
    }

}
